package mirfordevoservice.system.req.impl;

import mirfordevoservice.system.GameCenter.GameDataManager;
import mirfordevoservice.system.req.inter_face.ReqMessage;
import publicPackage.human.Role;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

/**
 * Created by Heart!
 *
 * @Author ZhangChaoJian
 * @Date ${Date}-19:54
 * Wants More Then Try Hard More!
 */

/**
 * 请求建立新的角色
 */
public class ReqCreateNewRole implements ReqMessage {

    @Override
    public void receive(ObjectInputStream in, Socket socket) {
    }

    @Override
    public void sendMsg(ObjectOutputStream out) {
    }

    @Override
    public void receiveAndSend(ObjectInputStream in, ObjectOutputStream out, Socket socket) {
        Role newRole;
        try {
            Object msgOne = in.readObject();//name
            Object msgTwo = in.readObject();//job
            Object msgThree = in.readObject();//sex
            Object msgFour = in.readObject();//id
            Object msgFive = in.readObject();//place
            newRole = GameDataManager.getInstance().createNewHumanAndCallBack((String) msgOne, (Integer) msgTwo, (Integer) msgThree, (Long) msgFour, (Integer) msgFive);
            out.writeObject(newRole);
            out.flush();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
